<?php
/**
 * Created by PhpStorm.
 * User: this
 * Date: 2018/12/24
 * Time: 14:16
 */
namespace app\admin\controller;
use app\admin\model\Message AS msg;
class Message extends Base{
    /**
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index(){
        $model = new msg();
        $info = $model->getPage('');
        $page = '';
        if ($info){
            foreach ($info as &$v){
                $v['mess_time'] = date('Y-m-d h:i:s',$v['mess_time']);
            }
            $page = $info->render();
        }
        $this->assign('msg',$info);
        $this->assign('site_title','留言列表-管理后台-百步园艺');
        $this->assign('page',$page);
        return $this->fetch('index');
    }

    public function del(){
        if(!$_GET){
            ajaxReturn(0,'参数错误!',-1);
        }
        if(gettype($_GET['mess_id']) == 'array'){
            $condition['mess_id'] = array('in',$_GET['mess_id']);
        }else{
            $condition['mess_id'] = $_GET['mess_id'];
        }
        $model = new msg;
        $result = $model->del($condition);
        if($result){
            ajaxReturn($_GET['mess_id'],'删除成功!',1);
        }else{
            ajaxReturn(0,'删除失败!',0);
        }
    }

    /**
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function show(){
        $mess_id = input('mess_id');
        $menu = new msg();
        $info = $menu->getOne(array('mess_id'=>$mess_id),'mess_id,mess_name,mess_phone,mess_content,mess_time');
        if($info){
            $info['time'] = date("Y-m-d H:i:s",$info['mess_time']);
        }
        $this->assign('info',$info);
        $this->assign('nav','留言详情');
        $this->assign('site_title','留言详情-管理后台-百步园艺');
        return $this->fetch('show');
    }
}